package com.baoxin.chenxixc4coach.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.baoxin.chenxixc4coach.R;
import com.baoxin.chenxixc4coach.bean.CoachRead;
import com.bumptech.glide.Glide;

import java.util.List;

public class CoachReadAdapter extends RecyclerView.Adapter<CoachReadAdapter.ViewHolder> {

    private List<CoachRead> coachReadList;
    private Context context;

    public CoachReadAdapter(Context context) {
        this.context = context;
    }

    public void setData(List<CoachRead> newsList){
        this.coachReadList = newsList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.coach_read,
                parent, false);
        final ViewHolder holder = new ViewHolder(view);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        CoachRead coachRead = coachReadList.get(position);
        holder.title.setText(coachRead.getTitle());
        Glide.with(context)
                .load(R.drawable.news)// news.getPicURL()
                .into(holder.pic);
        holder.title2.setText(coachRead.getTitle2());
    }

    @Override
    public int getItemCount() {
        return coachReadList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        View itemView;
        TextView title;
        ImageView pic;
        TextView title2;

        public ViewHolder(View itemView) {
            super(itemView);
            this.itemView = itemView;
            title = itemView.findViewById(R.id.title);
            pic = itemView.findViewById(R.id.pic);
            title2 = itemView.findViewById(R.id.title2);
        }
    }
}
